<template>
	<view>
		<view class="evaluate">
			<view class="evaluate_box">
				<view class="pingjia">
					<view v-if="cmtDetail.length !== 0">
						<view class="pingjia_box" v-for="(row, index) in cmtDetail" :key="index">
							<view class="box_top">
								<image :src="row.user.avatar" mode="" class="head"></image>
								<view class="right">
									<p class="name">{{ row.user.userName }}</p>
									<p class="p2">
										<text class="text1">{{ renderTimeYMDHMS(row.cmtTime)}}</text>
									</p>
									<p class="p3">
										<image src="/static/component/star/stars.png" v-for="s in scoreToInt(row.cmtScore)" :key="s" mode=""></image>
										<block v-if="scoreToInt(row.cmtScore) !== 5">
											<image src="/static/component/star/star-no.png" v-for="(s,h) in (5-scoreToInt(row.cmtScore))" :key="h" mode=""></image>
										</block>
									</p>
								</view>
							</view>
							<view class="ping_neirong">{{ row.cmtCont }}</view>
							<view class="ping_img" v-if="row.cmtImg !== null">
								<image :src="s" mode="" v-for="(s,x) in row.cmtImg" :key="x" @click="preview(row.cmtImg, x)"></image>
							</view>
							<view class="likeorreso">
								<view class="cmt_like">
									<image class="cmt_like_pic" src="/static/component/likeorcmt/likefalseicon.png"></image>
									<view class="cmt_like_num">{{row.cmtLikeNum}}</view>
								</view>
								<view class="cmt_reso">
									<image class="cmt_reso_pic" src="/static/component/likeorcmt/resoicon.png"></image>
									<view class="cmt_reso_num">{{row.cmtResoNum}}</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="bg-dark"></view>
		<!-- 评价 -->
		<view class="eva-section">
			<view class="e-header">
				<text class="tit">共鸣</text>
				<text class="tit-num">({{reso.length}})</text>
			</view> 
			<view class="eva-box" v-for="(row, index) in reso" :key="index">
				<image class="portrait" :src="row.user.avatar"></image>
				<view class="right">
					<text class="name">{{row.user.userName}}</text>
					<text class="time">{{renderTimeYMDHMS(row.resoTime)}}</text>
					<text class="con">{{row.resoCont}}</text>
					<view class="bot">
						<view class="reso_like">
							<image class="reso_like_pic" src="/static/component/likeorcmt/likefalseicon.png"></image>
							<view class="reso_like_num">{{row.resoLikeNum}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 底部输入栏 -->
		<view class="input-box">
			<view class="textbox">
				<view class="text-mode">
					<view class="box">
						<textarea auto-height="true" v-model="textMsg" id="textMsg" />
					</view>
				</view>
			</view>
			<label for="textMsg">
			<view class="send" @tap="sendText">
				<view class="btn">
					发送
				</view>
			</view>
			</label>
		</view>
	</view>
</template>

<script>
	export default {
		onLoad() {
			this.getCmtDetail(1);
			this.getCmtReso(1);
		},
		data() {
			return {
				cmtId: 1,
				//文字消息
				textMsg:'',
				cmtDetail: [],
				reso: [],
			}
		},
		methods: {
			//预览图片
			preview(imgs, index){
				uni.previewImage({
					current:index,
					urls:imgs
				})
			},
			//评分取整
			scoreToInt(actScore) {
				return Math.round(actScore);
			},
			//修改时间格式：年月日时分秒
			renderTimeYMDHMS(date) {
			  var dateee = new Date(date).toJSON();
			  return new Date(+new Date(dateee) + 8 * 3600 * 1000)
						.toISOString()
						.replace(/T/g, ' ')
						.replace(/\.[\d]{3}Z/, '') 
			},
			//获取评论详情
			getCmtDetail(cmtId) {
				uni.request({
					url: "http://ronin.fun:8888/act/cmt/detail",
					data: {
						cmtId: cmtId,
					},
					success: (res)=>  {
						this.cmtDetail.push(res.data.data);
						console.log(this.cmtDetail);
					}
				})
			},
			//获取评论共鸣
			getCmtReso(cmtId) {
				uni.request({
					url: "http://ronin.fun:8888/act/cmt/reso",
					data: {
						cmtId: cmtId,
					},
					success: (res)=>  {
						this.reso = res.data.data;
						console.log(this.reso);
					}
				})
			},
			// 发送文字消息
			sendText(){
				console.log(this.textMsg);
				this.postReso(this.cmtId, "aiqiu", this.textMsg);
			},
			// 发送评论共鸣
			postReso(cmtId, userId, resoCont) {
				uni.showLoading({
					title:"加载中..."
				})
				uni.request({
					url: "http://ronin.fun:8888/act/cmt/reso/post",
					method: 'POST',
					header: {
						'content-type': "application/x-www-form-urlencoded"
					},
					data: {
						cmtId: cmtId,
						userId: userId,
						resoCont: resoCont,
					},
					success: (res) => {
						uni.hideLoading()
						//成功
						if (res.data.code === 200) {
							setTimeout(()=>{
								// 服务端响应的 message 提示
								uni.showToast({
									title: "发送成功",
									icon: "none",
									position: 'bottom',
								})
								//延时关闭  加载中的 loading框
								uni.hideLoading()
							},1000)
							this.getCmtReso(cmtId)
						} else { 
							//不成功
							uni.hideLoading()
							// 服务端响应的 message 提示
							setTimeout(()=>{
								uni.showToast({
									title: "发送失败",
									icon: "none",
									position: 'bottom',
								})
								//延时关闭  加载中的 loading框
								uni.hideLoading()
							},1000)
						}
						this.textMsg = ''
					},
					fail: (res) => {
						// 服务端响应的 message 提示
						setTimeout(()=>{
							uni.showToast({
								title: "发送失败",
								icon: "none",
								position: 'bottom',
							})
							//延时关闭  加载中的 loading框
							uni.hideLoading()
						},1000)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.evaluate{
		padding: 0 4%;
		margin-bottom: 30upx;
		.evaluate_box{
			.pingjia {
				background-color: #ffffff;
				overflow: hidden;
				.pingjia_box {
					overflow: hidden;
					margin-top: 20upx;
					padding-bottom: 20upx;
					overflow: hidden;
					border-bottom: 1upx solid #f2f2f2;
					&:last-child {
						border-bottom: none;
						padding-bottom: 10upx;
					}
					.box_top {
						display: flex;
						.head {
							height: 80upx;
							max-width: 80upx;
							min-width: 80upx;
							flex: 1;
							border-radius: 50%;
							float: left;
						}
						.right {
							flex: 1;
							margin-left: 20upx;
							position: relative;
							.name {
								font-size: 26upx;
								font-family: Source Han Sans CN;
								font-weight: 400;
								color: rgba(0, 0, 0, 1);
							}
							.p2 {
								margin-top: 20upx;
								font-size: 24upx;
								font-family: Source Han Sans CN;
								font-weight: 400;
								color: rgba(156, 156, 156, 1);
								.text2 {
									margin-left: 50upx;
								}
							}
							.p3 {
								height: 35upx;
								position: absolute;
								right: 0;
								width: 200upx;
								top: 8upx;
								image {
									width: 35upx;
									height: 35upx;
									float: left;
									margin-left: 5upx;
								}
							}
						}
					}
					.ping_neirong {
						font-size: 28upx;
						margin-top: 20upx;
						font-family: Source Han Sans CN;
						font-weight: 500;
						color: rgba(0, 0, 0, 1);
						line-height: 50upx;
					}
					.ping_img {
						display: flex;
						flex-wrap: wrap;
						align-items: flex-start;
						align-content: flex-start;
						justify-content: space-between;
						margin-top: 20upx;
						&::after {
							content: '';
							max-width: 29vw;
							min-width: 29vw;
						}
						image {
							max-width: 29vw;
							min-width: 29vw;
							height: 29vw;
							border-radius: 10upx;
							margin-bottom: 20upx;
						}
					}
					.likeorreso {
						.cmt_like {
							display:inline-block;
							margin-left: 470upx;
							width: 80upx;
							height: 50upx;
							.cmt_like_pic {
								vertical-align: bottom;
								width: 50upx;
								height: 50upx;
							}
							.cmt_like_num {
								display:inline-block;
								font-size: 30upx;
								margin-left: 10upx;
								color: #555555;
							}
						}
						.cmt_reso {
							display:inline-block;
							margin-left: 50upx;
							.cmt_reso_pic {
								vertical-align: bottom;
								width: 50upx;
								height: 50upx;
							}
							.cmt_reso_num {
								display:inline-block;
								margin-left: 10upx;
								color: #555555;
							}
						}
					}
				}
			}
		}
	}
	.bg-dark {
		background-color: #f2f2f2;
		height: 50upx;
	}
	/* 评价 */
	.eva-section{
		display: flex;
		flex-direction: column;
		padding: 20upx 30upx;
		background: #fff;
		margin-bottom: 100upx;
		.e-header{
			display: flex;
			align-items: center;
			height: 70upx;
			font-size: $font-sm + 2upx;
			color: $font-color-light;
			.tit{
				font-size: $font-base + 5upx;
				color: $font-color-dark;
				margin-right: 4upx;
			}
			.tit-num{
				font-size: $font-base;
				margin-left: 10upx;
			}
			.tip{
				flex: 1;
				text-align: right;
			}
			.icon-you{
				margin-left: 10upx;
			}
		}
	}
	.eva-box{
		display: flex;
		padding: 20upx 0;
		.portrait{
			flex-shrink: 0;
			width: 80upx;
			height: 80upx;
			border-radius: 100px;
		}
		.right{
			flex: 1;
			display: flex;
			flex-direction: column;
			font-size: $font-base;
			color: $font-color-base;
			padding-left: 26upx;
			.con{
				margin-top: 10upx;
				font-size: $font-base;
				color: $font-color-dark;
				padding: 20upx 0;
			}
			.bot{
				display: flex;
				justify-content: space-between;
				font-size: $font-sm;
				color:$font-color-light;
				border-bottom: 1upx solid #f2f2f2;
			}
			.time{
				margin-top: 10upx;
			}
			.reso_like {
				display:inline-block;
				margin-left: 470upx;
				width: 80upx;
				height: 50upx;
				margin-bottom: 18upx;
				.reso_like_pic {
					vertical-align: bottom;
					width: 50upx;
					height: 50upx;
				}
				.reso_like_num {
					display:inline-block;
					font-size: 30upx;
					margin-left: 10upx;
					color: #555555;
				}
			}
		}
	}
	
	.input-box{
		width: 100%;
		min-height: 100upx;
		padding: 0 1%;
		background-color: #f2f2f2;
		display: flex;
		position: fixed;
		z-index: 20;
		bottom: 0;
		.send{
			//H5发送按钮左边距
			/* #ifdef H5 */
			margin-left: 20upx;
			/* #endif */
			flex-shrink: 0;
			width: 100upx;
			height: 100upx;
			display: flex;
			align-items: center;
			.btn{
				width: 90upx;
				height: 56upx;
				display: flex;
				justify-content: center;
				align-items: center;
				background:#B0E3FF;
				color: #fff;
				border-radius: 6upx;
				font-size: 24upx;
			}
		}
		.textbox{
			width: 100%;
			min-height: 70upx;
			margin-top: 15upx;
			.text-mode{
				width: 100%;
				min-height: 70upx;
				display: flex;
				background-color: #fff;
				border-radius: 40upx;
				.box{
					width: 100%;
					padding-left: 30upx;
					min-height: 70upx;
					display: flex;
					align-items: center;
					textarea{
						width: 100%;
					}
				}
				.em{
					flex-shrink: 0;
					width: 80upx;
					height: 70upx;
					display: flex;
					justify-content: center;
					align-items: center;
				}
			}
		}
	}
	
</style>
